View Javadoc

1   /**
2    * Copyright 2008 WebPhotos
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.webphotos.tools;
17  
18  import java.awt.MediaTracker;
19  import java.io.File;
20  import java.sql.*;
21  import javax.swing.*;
22  
23  public class Resolucao {
24  
25      public static void main(String args[]) {
26          TelaResolucao f = new TelaResolucao();
27  
28          f.setVisible(true);
29          f.iniciar();
30      }
31  }
32  
33  class TelaResolucao extends JFrame {
34  
35      private JTextArea texto;
36      private JTextArea instrucao;
37      private JLabel contador = new JLabel("0/0");
38      private JLabel bons = new JLabel("0");
39      private JLabel maus = new JLabel("0");
40  
41      public TelaResolucao() {
42          setSize(470, 400);
43          setDefaultCloseOperation(EXIT_ON_CLOSE);
44          getContentPane().setLayout(null);
45  
46          texto = new JTextArea();
47          instrucao = new JTextArea();
48          //texto.setLineWrap(true);
49          //texto.setWrapStyleWord(true);
50          JScrollPane scrTexto = new JScrollPane(texto);
51          JScrollPane scrInstrucao = new JScrollPane(instrucao);
52  
53          maus.setBounds(3, 3, 150, 20);
54          scrTexto.setBounds(3, 20, 450, 80);
55  
56          bons.setBounds(3, 110, 150, 20);
57          scrInstrucao.setBounds(3, 130, 450, 200);
58  
59          contador.setBounds(3, 335, 150, 20);
60  
61          getContentPane().add(bons);
62          getContentPane().add(maus);
63          getContentPane().add(scrTexto);
64          getContentPane().add(scrInstrucao);
65          getContentPane().add(contador);
66  
67      }
68  
69      public void iniciar() {
70          String url = "jdbc:mysql://192.168.0.2/saopaulosp";
71          Connection conn;
72          ResultSet rs1;
73          ResultSet rs2;
74          Statement st1;
75          Statement st2;
76          int albumID;
77          int fotoID;
78          ImageIcon foto;
79          int altura, largura;
80          int totalRegistros;
81          int ct = 0;
82          int ctB = 0;
83          int ctM = 0;
84          File f;
85          String msgErro;
86  
87          try {
88              Class.forName("com.mysql.jdbc.Driver").newInstance();
89              conn = DriverManager.getConnection(url, "root", "");
90              Statement st = conn.createStatement();
91              ResultSet rs = st.executeQuery("select count(*) from fotos");
92              rs.first();
93              totalRegistros = rs.getInt(1);
94              rs.close();
95              st.close();
96  
97              st1 = conn.createStatement();
98              rs1 = st1.executeQuery("select albumID from albuns order by albumID");
99  
100             while (rs1.next()) {
101                 albumID = rs1.getInt("albumID");
102                 st2 = conn.createStatement();
103                 rs2 = st2.executeQuery("select fotoID from fotos where altura=0 and altura=0 and albumID=" + albumID);
104                 while (rs2.next()) {
105                     ct++;
106                     contador.setText(ct + "/" + totalRegistros);
107                     fotoID = rs2.getInt("fotoID");
108                     String caminho = "F:/albuns_sp/" + albumID + "/" + fotoID + ".jpg";
109                     foto = new ImageIcon(caminho);
110 
111                     if (foto.getImageLoadStatus() == MediaTracker.COMPLETE) {
112                         ctB++;
113                         bons.setText("" + ctB);
114                         altura = foto.getIconHeight();
115                         largura = foto.getIconWidth();
116                         caminho = "update fotos set largura=" + largura + ", altura=" + altura + " where fotoID=" + fotoID + ";\n";
117                         instrucao.append(caminho);
118                     } else {
119                         ctM++;
120                         maus.setText("" + ctM);
121                         // que erro ocorreu ?
122                         msgErro = "";
123                         f = new File("F:/albuns_sp/" + albumID + "/" + fotoID + ".jpg");
124                         if (!f.exists()) {
125                             msgErro = " | arquivo não existe";
126                         }
127                         if (!f.isFile()) {
128                             msgErro = msgErro + " | não é arquivo";
129                         }
130                         if (!f.canRead()) {
131                             msgErro = msgErro + " | não pode ser lido";
132                         }
133                         caminho = albumID + "/" + fotoID + msgErro + "\n";
134                         texto.append(caminho);
135                     }
136                 }
137                 rs2.close();
138             }
139 
140         } catch (Exception e) {
141             texto.append("erro na leitura do driver " + e);
142         }
143     }
144 }